package br.com.ss.bean;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import br.com.ss.entity.Dog;
import br.com.ss.enumeration.EMensageError;
import br.com.ss.enumeration.parametros.EWindowParameter;
import br.com.ss.facade.DogFacade;
import br.com.ss.util.FacesUtil;


@ManagedBean(name = "dogCRUDBean")
@RequestScoped
public class DogCRUDBean extends AbstractMenageBean {
	
	@EJB
    private DogFacade dogFacade;

	private Dog dog;
	
 //############################################################################################################################3
	   
	
    @PostConstruct
    public void init() {
    	limpar();
    }
    
    private void limpar(){
    	dog = new Dog();
    }
    
 
    public void viewCreateDogs2() {
    	
    	Map<EWindowParameter, Object> parametros = new HashMap<EWindowParameter, Object>();
    	parametros.put(EWindowParameter.RESIZABLE, true);
    	parametros.put(EWindowParameter.DRAGGABLE, true);
    	parametros.put(EWindowParameter.MODAL, false);
    	
    	viewWindowCustomized("createDog", parametros);

    }

    
    public void createDog(){
        try {
//        	this.dog.setName(getNome());
//        	this.dog.setWeight(getPeso());
        	
            dogFacade.save(dog);
        } catch (EJBException e) {
           FacesUtil.criarMensagemErro(EMensageError.ERRO_AO_INCLUIR_, new Object[]{"DOG"});
        }     
        
        limpar();
    }

      
    //############################################################################################################################3
     
	public Dog getDog() {
		return dog;
	}


	public void setDog(Dog dog) {
		this.dog = dog;
	}

    
   
}
